package com.summer.sqlSession;

import com.summer.config.XMlConfigBuilder;
import com.summer.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws DocumentException, PropertyVetoException {
        //第一：使用dom4j解析配置文件 将解析出来的内容封装到Configuration中
        XMlConfigBuilder xMlConfigBuilder = new XMlConfigBuilder();
        Configuration configuration = xMlConfigBuilder.parseConfig(in);

        //第二：创建SqlSessionFactory对象 工厂类：生产sqlSession：会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }

}
